/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package utils;

/**
 *
 * @author Felipe Gutierrez
 */
import java.util.ArrayList;


import xmibase.XmiAttribute;

public class GenUtils extends FormatationUtils{

	public String getInstanceList(ArrayList<XmiAttribute> attributesList ){
		String aux = "";

		for( XmiAttribute attribute : attributesList) {

			if( attribute.getName().equals("id")) {
				aux += "setID( ((fieldToValueMap.get( \"ID\" )==null)? \"\":fieldToValueMap.get";
				aux += "(\"ID\").toString()));\n";
			}  else {
				if (attribute.isBO()) {
					aux += "set" + upperFirst(attribute.getName()) + "( (fieldToValueMap.get(\"" + attribute.getName() + "\")==null)? new ArrayList():(Collection)fieldToValueMap.get(\""+attribute.getName() + "\"));\n";
				} else {
					aux += "set"+ upperFirst(attribute.getName()) + "( ((fieldToValueMap.get(\"" + attribute.getName() + "\")==null)? \"\":fieldToValueMap.get(\"" + attribute.getName() + "\").toString()));\n";
				}
			}

		}
		return aux;
	}

	public String getAttributeType(XmiAttribute attribute) {
		if (attribute.getDataType() == null) {
			return "";
		} else {
			if (attribute.getUpperMultiplicity() == -1) {
				return "List " ;
						
			} else if(attribute.getUpperMultiplicity() == 1){
                return "List ";
            }

            else{
				return convertPrimitiveType(attribute.getDataType());
			}
		}

	}
}

